/**
 *  transformRequest & transformResponse转换逻辑
 *  定义一些列转换函数，然后依次执行，并把data和headers作为fn函数参数
*/
import { AxiosTransformer } from "../types";

export default function transform(data: any, headers: any, fns?: AxiosTransformer | AxiosTransformer[]): any {
  if(!fns) {
    return data
  }

  if(!Array.isArray(fns)) {
    fns = [fns]
  }

  fns.forEach(fn => {
    data = fn(data,headers)
  })

  return data;
}